import pygame, sys, math

from Block import Block

class PushBlock(Block):
    def __init__(self, image, pos = (0,0), blocksize = [50,50]):
        Block.__init__(self, image, pos, blocksize)
        self.offsetx = 0
        self.offsety = 0
        
        
    def push(self, player):
        print "he's touching me"
        if player.realx < self.realx and player.headingx == "right":
            self.speedx = player.speedx
            print "hit right"
        elif player.realx > self.realx and player.headingx == "left":
            self.speedx = player.speedx
            print "hit left"
        else:
            self.speedx = 0
        if player.realy > self.realy and player.headingy == "up":
            self.speedy = player.speedy
            print "hit up"
        elif player.realy < self.realy and player.headingy == "down":
            self.speedy = player.speedy
            print "hit down"
        else:
            self.speedy = 0
            
    def update(*args):
        self = args[0]
        self.playerspeedx = args[2]
        self.playerspeedy = args[3]
        self.scrollingx = args[4]
        self.scrollingy = args[5]
        playerx = args[6]
        playery = args[7]
        self.move()
        self.speedx =0
        self.speedy =0
           
    def move(self):
        #print "enemy", self.realx, self.speedx
        self.realx += self.speedx
        self.realy += self.speedy
            
        if self.scrollingx:
            self.offsetx -= self.playerspeedx
        if self.scrollingy:
            self.offsety -=  self.playerspeedy
        
        self.x = self.realx + self.offsetx
        self.y = self.realy + self.offsety
            
        self.rect.center = (round(self.x), round(self.y))